<template>
	<view :class="isDark?'darkBg':''">
		<cu-custom :bgColor="isDark?'bg-black':'bg-brown'" isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">历史借阅</block>
		</cu-custom>
		<view :class="isDark?'dark':''">
			<view>
				<view style="height: 545rpx; background-size: cover;  background-position: center;"
					:style="{backgroundImage:isDark?'url(https://web.cloudduolc.cn/image/adblack7.png)':'url(https://web.cloudduolc.cn/image/adwhite5.png)'}">	
					<ad unit-id="adunit-acfe943d38ee2b64" ad-type="video" :ad-theme="isDark?'black':'white'"></ad>
				</view>
				<view class="cu-bar  solid-bottom" style="font-weight:bold" :class="isDark?'dark':'bg-white'">
					<view class="action">
						<text class="cuIcon-titles text-brown"></text> 历史借阅
						<text class="cuIcon-search"></text>
					</view>
				</view>


				<view v-show="showEmptyIcon" style="text-align: center;font-size: 40rpx;margin-top: 20rpx;"
					:class="isDark?'darkIn':'bg-white'">


					<image src="../../../static/score/empty.png" style="width: 600rpx;height: 600rpx;margin-top: 0rpx;">
					</image>
				</view>
				<view class=" margin padding" v-for="(val,index) in totalList" :key="index"
					:class="isDark?'darkIn':'bg-white'">
					<view style="display: flex;">

						<view style="width:10rpx;">{{index+1}}</view>
						<view>
							<span style="margin-left: 65rpx;">书名：{{val.bookName}}</span>
							<view style="margin-top: 20rpx;margin-left: 65rpx;">
								索书号：{{val.indexNumber}}
							</view>
							<view style="margin-top: 20rpx;margin-left: 65rpx;">
								馆藏地：{{val.library}}
							</view>
							<view style="margin-top: 20rpx;margin-left: 65rpx;">
								借阅时间：{{val.borrowTime}}
							</view>
							<view style="margin-top: 20rpx;margin-left: 65rpx;">
								归还时间：{{val.returnTime}}
							</view>
						</view>
					</view>
				</view>
				<view class="padding margin-top flex flex-wrap " :class="isDark?'dark':'bg-white'">
					<button class="cu-btn round line" @click="refreshInfo()">
						<text class="cuIcon-refresh text-right" :class="isDark?'dark':''"></text></button>
				</view>
			</view>
		</view>
		<zmm-watermark>

		</zmm-watermark>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				array: [],
				index: 0,
				totalList: [],
				total: null,
				num: null,
				showEmptyIcon: false,
				isDark: this.isDark,
				page: 1


			}
		},
		onLoad() {

		},
		onShow() {
			let _this = this

			_this.setData()
			_this.refreshInfo()


		},
		methods: {
			setData() {
				let _this = this
				if (_this.totalList.length <= 0) {
					_this.showEmptyIcon = true
				} else {
					_this.showEmptyIcon = false
				}

			},
			onReachBottom() {
				let _this = this
				console.log("我已经滚动到底部了")
				_this.page = _this.page + 1
				_this.refreshInfo()
			},
			/**
			 * @description  请求数据
			 */
			refreshInfo: function() {
				let _this = this
				var userInfo = _this.$store.state.userInfo
				if (_this.$store.state.isExit == 1 | userInfo.password == "" || userInfo.password == null) {

					uni.showModal({
						title: 'Hi',
						content: '会话已过期，\n当前功能需要登录，是否要去登录?\n(该程序的用户信息只存在手机本地，当切出程序需要重新登录)',
						confirmText: "去登录",
						cancelText: "再逛会",
						success: function(res) {
							if (res.confirm) {
								_this.$Router.navigateTo("/pages/bind/login/index")
							} else if (res.cancel) {
								console.log("点击了取消")
							} else {
								console.log("点击了别的")
							}
						}
					});
					return
				}

				let form = {
					password: _this.$store.state.userInfo.password,
					page: _this.page
				}
				_this.$schoolApi.bookHistory(form).then(response => {
					//console.log(response.data)
					if (response.status == 0) {
						for (var i = 0; i < response.data.length; i++) {
							_this.totalList.push(response.data[i])
						}
						if (response.data.length <= 0) {
							uni.showToast({
								icon: 'none',
								title: '已经到底！',
								duration: 2000
							});
						} else {
							uni.showToast({
								icon: 'none',
								title: '成功获取数据',
								duration: 2000
							});
						}
						_this.setData()


					} else if (response.status != 608 && response.status != 603) {
						uni.showModal({
							title: '提示',
							content: response.msg,
							showCancel: false,
							success: function(res) {
								if (res.confirm) {

								} else if (res.cancel) {

								}
							}
						});
					}

				})



			}




		}

	}
</script>

<style>
	.tableTitle {
		float: right;
		margin-right: 50rpx;
		margin-top: 0rpx;
		width: 100rpx;
		font-size: 25rpx;
	}
</style>
